public class MotiongramY {
  private PImage frameL, frameR;
  private int currX;
  
  public MotiongramY(int w, int h) {
    this.frameL = createImage(w, h, RGB);
    this.frameR = createImage(w, h, RGB);
    this.currX = 0;
  }
  
  public void setMarks(float leftY, float rightY) {
    frameL.set(currX,(int)leftY,color(255,0,0));
    frameR.set(currX,(int)rightY,color(0,0,255));
  }
  
  public float[] process(PImage img, int thresh) {
    float[] result = new float[2*img.width];
    currX = (currX + 1) % frameL.width;
    for (int y = 0; y < img.height; y++) {
      int j = img.height + y;
      for (int x = 0; x < thresh; x++) {
        result[y] += brightness(img.get(x,y));
      }
      for (int x = thresh; x < img.width; x++) {
        result[j] += brightness(img.get(x,y));
      }
      result[y] /= img.width;
      result[j] /= img.width;
      frameL.set(currX, y, color(result[y]));
      frameR.set(currX, y, color(result[j]));
    }
    return result;
  }
  
  public void displayL(int x, int y) {
   // image(frameL,x,y);
  }
  
  public void displayR(int x, int y) {
 //   image(frameR,x,y);
  }
}
